package yf.mall.utils;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import yf.mall.vo.OrderDownVo;
import yf.mall.vo.OrderSumVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DownUtil {

    public static void download(HttpServletResponse response,Class clazz,List datas){
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=demo.xlsx");
        try {
            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
            WriteSheet writeSheet1 = EasyExcel.writerSheet(0, "数据").head(clazz).build();
            excelWriter.write(datas, writeSheet1);
            excelWriter.finish();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
